package com.cs.service;

import com.cs.mapper.HosregisterMapper;
import com.cs.pojo.Hosregister;
import com.cs.pojo.HosregisterExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.cs.resultVO.HosRegisterQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HosRegisterService {

    @Resource
    private HosregisterMapper hosregisterMapper;

    /**
     * 多条件分页查询
     * @param pageNum
     * @param pageSize
     * @param vo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public PageInfo<Hosregister> queryByPage(Integer pageNum, Integer pageSize, HosRegisterQueryVO vo) {
        HosregisterExample example = new HosregisterExample();
        HosregisterExample.Criteria criteria = example.createCriteria();
        if (vo != null) {
            if (vo.getrId() != null) {
                criteria.andHosrIdEqualTo(vo.getrId());
            }
            if (vo.getdName() != null && !"".equals(vo.getdName())) {
                criteria.andDNameLike(vo.getdName());
            }
            if (vo.getdClassroom() != null && !"".equals(vo.getdClassroom())) {
                criteria.andDClassroomLike(vo.getdClassroom());
            }
            if (vo.getrBeginDate() != null) {
                criteria.andHosrBegindateGreaterThanOrEqualTo(vo.getrBeginDate());
            }
            if (vo.getrEndDate() != null) {
                criteria.andHosrEnddateGreaterThanOrEqualTo(vo.getrEndDate());
            }
        }
        PageHelper.startPage(pageNum, pageSize);
        List<Hosregister> list = hosregisterMapper.selectByExample(example);
        return new PageInfo<>(list);
    }
}
